<template>
  <div class="table-container">
    <div class="table-breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>房源管理</el-breadcrumb-item>
        <el-breadcrumb-item>房源列表</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="table-search">
      <el-row>
        <el-input
          style="width: 500px;margin-right: 10px"
          placeholder="楼盘名称,行政区名称,房源标题"
          v-model="keyword"
          clearable
          @clear="resetData"
        >
        </el-input>
        <el-button type="primary" @click="resetData">搜索</el-button>
      </el-row>
    </div>
    <div class="table-content">
      <div class="table-bar">
        <!--        <el-button type="primary" @click="handleAdd">新增文章</el-button>-->
        <!--        <el-button type="danger" @click="handleBatchDel">批量删除</el-button>-->
      </div>
      <el-table
        border
        empty-text="当前数据空空如也"
        ref="multipleTable"
        :data="houses"
        tooltip-effect="dark"
        style="width: 100%"
        @select="selectedRow"
        @select-all="selectedAll"
      >
        <el-table-column prop="id" label="序号" width="100"></el-table-column>
        <el-table-column prop="build_code" label="楼盘检索码" width="100"></el-table-column>
        <el-table-column prop="build_id" label="楼盘ID" width="120"></el-table-column>
        <el-table-column prop="build_name" label="楼盘名称"></el-table-column>
        <el-table-column prop="region_name" label="行政区名称"></el-table-column>
        <el-table-column prop="sale_id" label="房源ID" width="100"></el-table-column>
        <el-table-column prop="sale_no" label="房源编码"></el-table-column>
        <el-table-column prop="sale_subject" label="房源标题">
        </el-table-column>
        <el-table-column prop="sale_total_price" label="总价(万)" width="80">
        </el-table-column>
        <el-table-column prop="sale_type" label="类型" width="100">
        </el-table-column>
        <el-table-column prop="sale_unit_price" label="单价（元）" width="100">
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="150">
          <template slot-scope="scope">
            <el-button
              size="mini"
              style="margin-right: 5px"
              @click="handleDetail(scope.$index, scope.row)">详情
            </el-button>
            <el-popconfirm
              confirm-button-text='确定'
              cancel-button-text='点错了'
              icon="el-icon-info"
              icon-color="red"
              title="这是一段内容确定删除吗？"
              @confirm="handleDelete(scope.index,scope.row)"
            >
              <el-button slot="reference" type="danger" size="mini">删除</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      <div class="page-nav">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page"
          :page-sizes="[10, 20, 30, 50,100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
    <el-dialog title="房源详情" :visible.sync="dialogTableVisible">
      <el-tabs v-model="activeName">
        <el-tab-pane label="基本信息" name="first">
          <el-form ref="form" :model="house" label-width="100px">
            <el-form-item label="楼盘检索码:">
              <span>{{house.build_code}}</span>
            </el-form-item>
            <el-form-item label="楼盘ID:">
              <span>{{house.build_id}}</span>
            </el-form-item>
            <el-form-item label="楼盘名称:">
              <span>{{house.build_name}}</span>
            </el-form-item>
            <el-form-item label="门店:">
              <span>{{house.dept_id}}</span>
            </el-form-item>
            <el-form-item label="商铺地址:">
              <span>{{house.trade_addr}}</span>
            </el-form-item>
            <el-form-item label="记录日期:">
              <span>{{house.creation_time}}</span>
            </el-form-item>
            <el-form-item label="车位数量:">
              <span>{{house.garage_amount}}</span>
            </el-form-item>
            <el-form-item label="花园面积:">
              <span>{{house.garden_area}}</span>
            </el-form-item>
            <el-form-item label="房屋结构:">
              <span>{{house.sale_struct}}</span>
            </el-form-item>
            <el-form-item label="厅结构:">
              <span>{{house.hall_structure}}</span>
            </el-form-item>
            <el-form-item label="状态:">
              <span v-if="house.sale_status == 1">有效</span>
              <span v-if="house.sale_status == 2">封盘</span>
              <span v-if="house.sale_status == 3">暂缓</span>
              <span v-if="house.sale_status == 4">预定</span>
              <span v-if="house.sale_status == 5">内成交</span>
              <span v-if="house.sale_status == 7">注销</span>
              <span v-if="house.sale_status == 101">转售</span>
              <span v-if="house.sale_status == 102">转租</span>
              <span v-if="house.sale_status == 103">转有效</span>
              <span v-if="house.sale_status == 104">转私盘</span>
            </el-form-item>
            <el-form-item label="写字楼级别:">
              <span>{{house.office_level}}</span>
            </el-form-item>
            <el-form-item label="是否可分割:">
              <span v-if="house.is_seperator == 1">是</span>
              <span v-if="house.is_seperator == 0">否</span>
            </el-form-item>
            <el-form-item label="是否邻街:">
              <span v-if="house.sale_street == 1">是</span>
              <span v-if="house.sale_street == 0">否</span>
            </el-form-item>
            <el-form-item label="物业费:">
              <span>{{house.sale_property}}</span>
            </el-form-item>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="房源信息" name="fourth">
          <el-form ref="form" :model="house" label-width="100px">
            <el-form-item label="房源ID:">
              <span>{{house.sale_id}}</span>
            </el-form-item>
            <el-form-item label="房源编码:">
              <span>{{house.sale_no}}</span>
            </el-form-item>
            <el-form-item label="房源标题:">
              <span>{{house.sale_subject}}</span>
            </el-form-item>
            <el-form-item label="所在行政区:">
              <span>{{house.region_name}}</span>
            </el-form-item>
            <el-form-item label="行政区ID:">
              <span>{{house.sale_reg}}</span>
            </el-form-item>
            <el-form-item label="建筑面积:">
              <span>{{house.sale_area}}平方米</span>
            </el-form-item>
            <el-form-item label="配套及特色:">
              <span>{{house.sale_charact}}</span>
            </el-form-item>
            <el-form-item label="房源朝向:">
              <span>{{house.sale_direct}}</span>
            </el-form-item>
            <el-form-item label="几户:">
              <span>{{house.sale_doors}}户</span>
            </el-form-item>
            <el-form-item label="装修:">
              <span>{{house.sale_fitment}}</span>
            </el-form-item>
            <el-form-item label="房勘:">
              <span v-if="house.sale_explrth == 1">已勘</span>
              <span v-if="house.sale_explrth == 0">未勘</span>
            </el-form-item>
            <el-form-item label="房勘日期:">
              <span>{{house.explrth_datetime}}</span>
            </el-form-item>
            <el-form-item label="所在楼层:">
              <span>{{house.sale_floor}}楼</span>
            </el-form-item>
            <el-form-item label="现状(按揭):">
              <span>{{house.sale_mortgage}}</span>
            </el-form-item>
            <el-form-item label="是否发布:">
              <span v-if="house.sale_publish == 1">已发布</span>
              <span v-if="house.sale_publish == 0">未发布</span>
            </el-form-item>
            <el-form-item label="产权:">
              <span>{{house.sale_right}}</span>
            </el-form-item>
            <el-form-item label="环域:">
              <span>{{house.sale_round}}</span>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="房屋信息" name="sex">
          <el-form ref="form" :model="house" label-width="100px">
            <el-form-item label="年度:">
              <span>{{house.sale_year}}</span>
            </el-form-item>
            <el-form-item label="片区:">
              <span>{{house.section_name}}</span>
            </el-form-item>
            <el-form-item label="套内面积:">
              <span>{{house.sale_innerarea || 0}}平方米</span>
            </el-form-item>
            <el-form-item label="售价:">
              <span>{{house.sale_total_price}}万元</span>
            </el-form-item>
            <el-form-item label="类型:">
              <span>{{house.sale_type}}</span>
            </el-form-item>
            <el-form-item label="单价:">
              <span>{{house.sale_unit_price}}元</span>
            </el-form-item>
            <el-form-item label="几房:">
              <span>{{house.sale_room}}房</span>
            </el-form-item>
            <el-form-item label="几厅:">
              <span>{{house.sale_floors}}厅</span>
            </el-form-item>
            <el-form-item label="几梯:">
              <span>{{house.sale_ladder}}梯</span>
            </el-form-item>
            <el-form-item label="几卫:">
              <span>{{house.sale_wei}}厅</span>
            </el-form-item>
            <el-form-item label="几阳台:">
              <span>{{house.sale_yang}}阳台</span>
            </el-form-item>
            <el-form-item label="用途:">
              <span>{{house.sale_useage}}</span>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="经纪人信息" name="five">
          <el-form ref="form" :model="house" label-width="100px">
            <el-form-item label="ID:">
              <span>{{house.user_id}}</span>
            </el-form-item>
            <el-form-item label="姓名:">
              <span>{{house.user_name}}</span>
            </el-form-item>
            <el-form-item label="电话:">
              <span>{{house.user_mobile}}</span>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="视频/图集" name="second">
          <el-form ref="form" :model="house" label-width="100px">
            <el-form-item label="缩略图:">
              <el-image
                style="width: 100px; "
                :src="house.thumb_url"
                :preview-src-list="[house.thumb_url]">
              </el-image>
            </el-form-item>
            <el-form-item label="图片张数:">
              <span>{{house.sale_map}}</span>
            </el-form-item>
            <el-form-item label="图片集:">
              <el-image
                v-for="(photo,index) in imgArr"
                :key="index"
                style="width: 100px;margin-right: 5px;"
                :src="photo"
                :preview-src-list="imgArr">
              </el-image>
            </el-form-item>
            <el-form-item label="视频数量:">
              <span>{{house.video_num}}</span>
            </el-form-item>
            <el-form-item label="视频:">
              <template v-if="Array.isArray(house.vedio_info)">
                <div class="video-container" v-for="(vedio,index1) in house.vedio_info" :key="index1">
                  <div class="video">
                    <el-image
                      style="width: 100px;margin-right: 5px "
                      :src="vedio.PHOTO_ADDR">
                    </el-image>
                    <i ref="btn" style="font-size:35px;position: absolute; top: 19px;left: 30px;color: greenyellow;"
                       slot="reference" class="el-icon-video-play"
                       @click="handlePlayer(vedio.VIDEO_ADDR)"></i>
                  </div>
                </div>
              </template>
              <template v-else>
                <div class="video-container" v-if="house.vedio_info">
                  <div class="video">
                    <el-image
                      style="width: 100px;margin-right: 5px "
                      :src="house.vedio_info.PHOTO_ADDR">
                    </el-image>
                    <i ref="btn" style="font-size:35px;position: absolute; top: 19px;left: 30px;color: greenyellow;"
                       slot="reference" class="el-icon-video-play"
                       @click="handlePlayer(house.vedio_info.VIDEO_ADDR)"></i>
                  </div>
                </div>
              </template>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="VR" name="third">
          <el-form ref="form" :model="house" label-width="100px">
            <template v-for="vr in house.panorama_photo_array">
              <el-form-item label="VR编号:">
                <a :href="vr.PANORAMA_ADDR" target="_blank">查看VR({{vr.VR_DEPT_ID}})</a>
              </el-form-item>
            </template>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="其它信息" name="seven">
          <el-form ref="form" :model="house" label-width="100px">
            <el-form-item label="地下面积:">
              <span>{{house.ug_area}}</span>
            </el-form-item>
            <el-form-item label="地下类型:">
              <span>{{house.ug_type}}</span>
            </el-form-item>
            <el-form-item label="是否有钥匙:">
              <span v-if="house.sale_key == 1">有</span>
              <span v-else-if="house.sale_key == 0">没有</span>
              <span v-else >没有</span>
            </el-form-item>
            <el-form-item label="钥匙编号:">
              <span>{{house.sale_key_num}}</span>
            </el-form-item>
            <el-form-item label="富文本:">
              <span>{{house.rich_text}}</span>
            </el-form-item>
            <el-form-item label="内部备注:">
              <span>{{house.sale_memo}}</span>
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
    <el-dialog title :visible.sync="dialogPlay" width="30%" @close="closeDialog">
      <video :src="videoUrl" controls autoplay class="video" ref="dialogVideo"
             width="100%"></video>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        page: 1,
        pageSize: 10,
        total: 0,
        keyword: '',
        houses: [],
        house: {},
        dialogTableVisible: false,
        activeName: 'first',
        multipleSelection: [],
        dialogPlay: false,
        videoUrl: '',
        imgArr:[]
      }
    },
    mounted() {
      this.queryList();
    },
    methods: {

      handleClose(done) {
        done();
      },

      handlePlayer(url) {
        this.dialogPlay = true;
        this.videoUrl = url;
      },

      closeDialog() {
        this.videoUrl = "";
      },
      handleAdd() {
        this.$router.push({name: 'addArticle'})
      },
      handleEdit(index, row) {
        const id = row.id;
        this.$router.push({name: 'editArticle', query: {id}});
      },
      handleDetail(index, row) {
        this.imgArr = []
        this.$http.post('/api/root/JlbRoom/view', {
          id:row.id,
        }).then(rest => {
          this.house = rest.data;
          rest.data.photo_array.map(item=>{
            this.imgArr.push(item.PHOTO_ADDR)
          })
          this.dialogTableVisible = true;
        })
      },
      handleDelete(index, row) {
        console.log(row,'ididid');
        this.toDelete(row.id);
      },
      handleBatchDel() {
        if (this.multipleSelection.length < 1) {
          this.$message.error("请先勾选需要删除的文章！");
          return;
        }
        this.$confirm('确定要执行批量删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.toDelete(this.multipleSelection.join(","))
        }).catch(() => {
          console.log('放弃删除')
        });

      },
      selectedRow(selection, row) {
        this.multipleSelection = [];
        const _ths = this;
        selection.map(function (item) {
          _ths.multipleSelection.push(item.id);
        })
      },
      selectedAll(rows) {
        if (rows.length === 0) {
          this.multipleSelection = [];
        } else {
          const _ths = this;
          rows.map(function (item) {
            if (!_ths.multipleSelection.includes(item.id)) {
              _ths.multipleSelection.push(item.id);
            }
          })
        }
      },

      handleSizeChange(val) {
        this.pageSize = val;
        this.page = 1;
        this.queryList()
      },
      handleCurrentChange(val) {
        this.page = val;
        this.queryList();
      },
      queryList() {
        this.$http.post('/api/root/JlbRoom/index', {
          page: this.page,
          pagesize: this.pageSize,
          keyword: this.keyword
        }).then(rest => {
          if (rest.code == 1) {
            this.houses = rest.data.list?rest.data.list:[];
            this.total = rest.data.total;
          }
        })
      },
      toDelete(id_lst) {
        this.$http.post('/api/root/JlbRoom/del', {
          id: id_lst,
        }).then(rest => {
          if (rest.code == 1) {
            this.queryList();
            this.multipleSelection = [];
            this.$message.success('删除成功');
          } else {
            this.$message.error("删除失败");
          }
        })
      },
      resetData() {
        this.page = 1;
        this.queryList();
      }
    }
  }
</script>
<style lang="less" scoped>
  @import 'index.less';

  .el-form-item {
    margin-bottom: 0;
  }

  .video-container {


    .video {
      width: 100px;
      cursor: pointer;
    }
  }
</style>
